\begin{tikzpicture}

\definecolor{darkgray176}{RGB}{176,176,176}
\definecolor{green01270}{RGB}{0,127,0}
\definecolor{lightgray204}{RGB}{204,204,204}

\begin{axis}[
legend cell align={left},
legend style={fill opacity=0.8, draw opacity=1, text opacity=1, draw=lightgray204},
tick align=outside,
tick pos=left,
title={Masked line demo},
unbounded coords=jump,
x grid style={darkgray176},
xmin=-0.3, xmax=6.3,
xtick style={color=black},
y grid style={darkgray176},
ymin=-1.0959515, ymax=1.0993605,
ytick style={color=black}
]
\addplot [ultra thick, red]
table {%
0 0
0.4 0.38941834
0.8 0.71735609
1.2 0.93203909
1.6 0.9995736
2 0.90929743
2.4 0.67546318
2.8 0.33498815
3.2 -0.058374143
3.6 -0.44252044
4 -0.7568025
4.4 -0.95160207
4.8 -0.99616461
5.2 -0.88345466
5.6 -0.63126664
6 -0.2794155
};
\addlegendentry{No mask}
\addplot [thick, green01270]
table {%
0 0
0.4 nan
0.8 nan
1.2 nan
1.6 -0.058374143
2 -0.7568025
2.4 -0.99616461
2.8 -0.63126664
3.2 0.1165492
3.6 nan
4 nan
4.4 nan
4.8 -0.17432678
5.2 -0.82782647
5.6 -0.97917773
6 -0.53657292
};
\addlegendentry{Masked if > 0.5}
\addplot [semithick, blue, mark=*, mark size=5, mark options={solid}, only marks]
table {%
0 0
0.4 0.93203909
0.8 0.67546318
1.2 -0.44252044
1.6 nan
2 -0.2794155
2.4 0.79366786
2.8 0.85459891
3.2 -0.17432678
3.6 nan
4 nan
4.4 0.59207351
4.8 0.96565778
5.2 0.10775365
5.6 nan
6 nan
};
\addlegendentry{Masked if < -0.5}
\end{axis}

\end{tikzpicture}
